<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html xmlns:th="" lang="zh-CN">
<%@include file="/WEB-INF/pages/base/include.jsp"%>
<body>
<div id="wrapper">
    <%@include file="/WEB-INF/pages/base/menu.jsp"%>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">商城列表</h3>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12 col-md-12">
                <div class="panel panel-default">
                    <div class="panel-heading">商城列表</div>
                    <div class="panel-body inner-body">
                        <div class="main-box-search">
                            <form method="post" name="from1" id="searchForm">
                                <div class="search-row">
                                    <input type="hidden" name="" value="">
                                    <div class="col-lg-2 col-md-6" style="margin-bottom:15px; padding-left:0px;">
                                        <input class="form-control" type="text" name="orderId" id="mallId"
                                               placeholder="请输入商城id查询">
                                    </div>
                                    <div class="col-lg-3 col-md-6" style=" margin-bottom:15px; padding-left:0px;">
                                        <input class="form-control" type="text" name="orderId" id="mallName"
                                               placeholder="请输入商城名称查询">
                                    </div>
                                    <div class="col-lg-2 col-md-6" style=" margin-bottom:15px;">
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="dataTable_wrapper">
                            <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <thead>
                                <tr>
                                	<th class="text-center" style="width:4%;">商城id</th>
                                    <th class="text-center" style="width:6%;">商城名称</th>
                                    <th class="text-center" style="width:6%;">商城首页名称</th>
                                    <th class="text-center" style="width:4%;">商城logo</th>
                                    <th class="text-center" style="width:6%;">商城色调</th>
                                    <th class="text-center" style="width:8%;">联系电话</th>
                                    <th class="text-center" style="width:8%;">创建时间</th>
                                    <th class="text-center" style="width:4%;">操作</th>
                                </tr>
                                </thead>
                                <tbody  id="mallList">
                                </tbody>
                            </table>
                        </div>
                        <div class="text-right">
                            <ul class="pagination" id="pagination">
                                <li><a href="javascript:void(0);" onclick="" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
				                <li><a  href="javascript:void(0);" onclick="" >1</a></li>
				                <li><a href="javascript:void(0);" onclick=""  aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
	searchCase(0,1);
	$('#searchForm').change(function(e) {
		searchCase(1,1);
	})
	//搜索微商
	function searchCase(flag,page) {
		var type = "${type}";
		if(type == "3"){
			alert("当前账号无权限查看此功能");
			return;
		}
		
		var pageSize= 10;
		
		var mallId = null;
		var mallName = null;
		
		if(flag == 1){
			mallId = $("#mallId").val();
			mallName = $("#mallName").val();
		}
		
		var baseURL = "${webPath}/mall/list";
	    var json_package = {
	        "head": {},
	        "body": {
	        	"mallId":mallId,
	        	"mallName":mallName,
	            "page": page,
	            "pageSize": pageSize
	        }
	    }
	    $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
	        if (typeof result == 'string') result = JSON.parse(result);
	        if (result.body.result == '1') {
	            alert(result.body.description)
	            $("#mallList").empty();
	        } else {
	        	$("#mallList").empty();
	        	var list = result.body.list;
	        	var count = result.body.count;
	        	var str = "";
	        	if(list.length<=0){
	        		return
	        	}
	        	for(var i=0;i<list.length;i++){
	        		str += '<tr>';
	        		str += '	<td class="text-center">'+list[i].id+'</td>';
	        		str += '	<td class="text-center">'+list[i].mallName+'</td>';
	        		str += '	<td class="text-center">'+list[i].companyName+'</td>';
	        		str += '	<td class="text-center"><img src="'+list[i].mallLogo+'" width="30px"></td>';
	        		str += '	<td class="text-center">'+list[i].mallColor+'</td>';
	        		str += '	<td class="text-center">'+list[i].contactPhone+'</td>';
	        		str += '	<td class="text-center">'+list[i].createTime+'</td>';
	        		str += '	<td class="text-center">';
					str += '		<button class="btn btn-default  deliver_goods" onclick=modify('+list[i].id+')>修改</button>';
					//str += '		<a class="btn btn-default" href="${webPath}toMallProduct/'+list[i].mallUuid+'">商城商品管理</a>';
					str += '	</td>';
	        		str += '</tr>';
	        	}
	        	$("#mallList").append(str);
	        	
	        	$("#pagination").empty();
	        	var pageString = "";
	        	var currentPage = page;
	        	var sumPage = Math.ceil(count/pageSize);
	        	pageString += '<li><a href="javascript:void(0);" onclick=searchCase(1,'+(currentPage-1)+') aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>';
	        	for(var i=1;i<=sumPage;i++){
	        		if(currentPage == i){
        				pageString += '<li><a href="javascript:void(0);" onclick=searchCase(1,'+i+') class="active">'+i+'</a></li>';
        			}else{
        				pageString += '<li><a href="javascript:void(0);" onclick=searchCase(1,'+i+')>'+i+'</a></li>';
        			}
	        	}
	        	if(sumPage==currentPage){
	        		pageString += '<li><a href="javascript:void(0);" onclick=searchCase(1,'+(currentPage)+') aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>';
	        	}else{
	        		pageString += '<li><a href="javascript:void(0);" onclick=searchCase(1,'+(currentPage+1)+') aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>';
	        	}
	        	
	        	$("#pagination").append(pageString);
	        }
	    })
	}
	
	function modify(mallId) {
        window.location.href="${webPath}toMallEdit/"+mallId;
    }
	
    function delUser(r) {
        $("table").index($(r).parent().parent());
        $(r).parent().parent().remove();
    }
</script>
</body>
</html>
